﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using webApi.models;
using webApi.Services;

namespace webApi.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    [EnableCors("any")] //配置跨域
    public class TestController : Controller
    {
        public UserService UserService { get; }

        //构造函数
        public TestController(UserService userService) {
            UserService = userService;
        }

        [HttpGet]
        public ActionResult<TestPostViewModel> Get()
        {
            IUserService userService = new UserService();
            return Ok(new TestPostViewModel { I = 1, Name = "Bear" });
        }

        [HttpGet]
        public string Get1()
        {

            return UserService.GetUserName();
        }

        [HttpPost]
        public TestPostViewModel Post(TestPostViewModel model) //用实体接受入参
        {
            return model;
        }

        [HttpPut]
        public string Put()
        {
            return "Put";
        }

        [HttpDelete]
        public string Delete()
        {
            return "Delete";
        }
    }
}
